// var mysql  = require('mysql')
// var connection = mysql.createConnection({
// 	host: '101.200.236.244',
// 	user: 'wts',
// 	password: '123456',
// 	database: 'village',
// 	port: '3306'
// })
// connection.connect(function error(error) {
// 	if(error) {
// 		console.log(error)
// 		return
// 	}
// 	console.log('数据库连接成功')
// })
// var userAdd = 'INSERT INTO user(name,avatar) VALUES (?,?)';
// var userAdd_params =  ['wts5','fdf']
// connection.query(userAdd,userAdd_params,function (err, result) {
// 	if(err) {
// 		console.log('error:', err.message)
// 	}
// 	console.log('--------插入-------')
// 	console.log('插入数据',result)
// 	console.log('-------end-------')
// })
var mysql = require('mysql');

var pool = mysql.createPool({
	host: '101.200.236.244',
	user: 'wts',
	password: '123456',
	database: 'village',
	port: '3306'
});

function query (sql, param, callback) {
	pool.getConnection(function (err, connection) {
		connection.query(sql, param, function(err, rows, fields) {
			if (err) {
				throw err;
			}

			callback(rows, fields)
			connection.release()
		})
	})
}
exports.query = query
// pool.getConnection(function(err,connection){
    
//     connection.query('SELECT * FROM user',function(err,result){
//         //console.log(err);
//         console.log(result);
//         connection.release();
//     });

// })